package org.eclipseuseradmin.internal.ui.security;

import java.security.Principal;
import java.security.acl.Group;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

public class RolesPrincipal implements Group {

	private String name;

	private List<RolePrincipal> members = new ArrayList<RolePrincipal>();

	public RolesPrincipal(String name) {
		this.name = name;
	}

	public boolean addMember(Principal member) {

		if (members.contains(member)) {
			return false;
		}

		members.add((RolePrincipal) member);
		return true;
	}

	public boolean isMember(Principal member) {
		return members.contains(member);
	}

	public Enumeration<RolePrincipal> members() {
		return Collections.enumeration(members);
	}

	public boolean removeMember(Principal member) {

		if (!members.contains(member)) {
			return false;
		}

		members.remove(member);
		return true;
	}

	public String getName() {
		return name;
	}

}
